/*
ID:luongho3
LANG:JAVA
TASK:palsquare
 */
package usaco.training.chap1.sec2;

import java.io.File;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Scanner;

public class palsquare {

	static int B;

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("palsquare.in"));
		PrintStream ps = new PrintStream(new File("palsquare.out"));
		System.setOut(ps);
		B = scanner.nextInt();
		for (int i=1;i<=300;++i) {
			String s = i + "";
			BigInteger b = new BigInteger(s);
			BigInteger square = b.multiply(b);
			if (palin(square.toString(B))) {
				System.out.println(b.toString(B).toUpperCase() + " " + square.toString(B).toUpperCase());
			}
		}

	}

	private static boolean palin(String string) {
		int len = string.length();
		int st = 0;
		int en = len - 1;
		while (st < en) {
			if (string.charAt(st) == string.charAt(en)) {
				st++;
				en--;
				continue;
			}
			else {
				return false;
			}
		}
		return true;
	}

}
